<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="支付方式" prop="paytype">
        <el-input
          v-model="queryParams.paytype"
          placeholder="请输入支付方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组" prop="group">
        <el-input
          v-model="queryParams.group"
          placeholder="请输入分组"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="listorderNum">
        <el-input
          v-model="queryParams.listorderNum"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ui:list_order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list_orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column  label="拼单订单序号" align="center" prop="listorderId" />
      <el-table-column label="支付方式" align="center" prop="paytype" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="拼单商品名称" align="center" prop="listproName" />
      <el-table-column label="拼单商品" align="center" prop="listproType" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.listproType==1">拼单商品</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="配送方式" align="center" prop="deliveryType" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.deliveryType==1">商家配送</el-tag>
          <el-tag v-if="scope.row.deliveryType==2">用户自提</el-tag>
        </template>
      </el-table-column>
     
      <!-- <el-table-column label="地址id" align="center" prop="addrId" /> -->
      <el-table-column label="商品描述" align="center" prop="listproTitle" />
      <el-table-column label="商品图片" align="center" prop="listproImg">
        <template slot-scope="scope">
          <image-preview :src="scope.row.listproImg" :width="50" :height="50"/>
        </template>
      </el-table-column>>
      <el-table-column label="分组" align="center" prop="group" />
      <el-table-column label="订单编号" align="center" prop="listorderNum" />
      <el-table-column label="拼单发起时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="拼单结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="拼单成功时间" align="center" prop="finshTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finshTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发货时间" align="center" prop="deliveryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="finallyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finallyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单价" align="center" prop="listproReprice" />
      <el-table-column label="数量" align="center" prop="count" />
      <el-table-column label="总价" align="center" prop="totalprice" />
      <el-table-column label="状态" align="center" prop="state">
        <template  slot-scope="scope">
          <el-tag v-if="scope.row.state==0" type="danger">拼单失败</el-tag>
          <el-tag v-if="scope.row.state==1" type="info">待付款</el-tag>
          <el-tag v-if="scope.row.state==2" type="warning">待发货</el-tag>
          <el-tag v-if="scope.row.state==3" size="medium ">待收货(已发货)</el-tag>
          <el-tag v-if="scope.row.state==4" type="success">已签收</el-tag>
          <el-tag v-if="scope.row.state==5" type="info">待拼单</el-tag>
          <el-tag v-if="scope.row.state==6" type="success">拼单成功</el-tag>
          <el-tag v-if="scope.row.state==7" type="success">订单完成</el-tag>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

   
  </div>
</template>

<script>
import { listList_order, getList_order, delList_order, addList_order, updateList_order } from "@/api/ui/list_order";

export default {
  name: "List_order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 拼单商品订单管理表格数据
      list_orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payId: null,
        group: null,
        listorderNum: null,
        state: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payId: [
          { required: true, message: "支付id不能为空", trigger: "blur" }
        ],
        shopId: [
          { required: true, message: "店铺id不能为空", trigger: "blur" }
        ],
        listproId: [
          { required: true, message: "拼单商品id不能为空", trigger: "blur" }
        ],
        addrId: [
          { required: true, message: "地址id不能为空", trigger: "blur" }
        ],
        memberId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
        commentId: [
          { required: true, message: "评论id不能为空", trigger: "blur" }
        ],
        group: [
          { required: true, message: "分组不能为空", trigger: "blur" }
        ],
        listorderNum: [
          { required: true, message: "订单编号不能为空", trigger: "blur" }
        ],
        startTime: [
          { required: true, message: "拼单发起时间不能为空", trigger: "blur" }
        ],
        endTime: [
          { required: true, message: "拼单结束时间不能为空", trigger: "blur" }
        ],
        finshTime: [
          { required: true, message: "拼单成功时间不能为空", trigger: "blur" }
        ],
        deliveryTime: [
          { required: true, message: "发货时间不能为空", trigger: "blur" }
        ],
        finallyTime: [
          { required: true, message: "完成时间不能为空", trigger: "blur" }
        ],
        oneprice: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        count: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        totalprice: [
          { required: true, message: "总价不能为空", trigger: "blur" }
        ],
        state: [
          { required: true, message: "状态 0:拼单失败1:待付款 2:待发货 3:待收货(已发货) 5:成功 6:待拼单7拼单成功不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询拼单商品订单管理列表 */
    getList() {
      this.loading = true;
      listList_order(this.queryParams).then(response => {
        console.log(response)
        this.list_orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        listorderId: null,
        payId: null,
        shopId: null,
        listproId: null,
        addrId: null,
        memberId: null,
        commentId: null,
        group: null,
        listorderNum: null,
        startTime: null,
        endTime: null,
        finshTime: null,
        deliveryTime: null,
        finallyTime: null,
        oneprice: null,
        count: null,
        totalprice: null,
        state: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.listorderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加拼单商品订单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const listorderId = row.listorderId || this.ids
      getList_order(listorderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改拼单商品订单管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.listorderId != null) {
            updateList_order(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addList_order(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const listorderIds = row.listorderId || this.ids;
      this.$modal.confirm('是否确认删除拼单商品订单管理编号为"' + listorderIds + '"的数据项？').then(function() {
        return delList_order(listorderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ui/list_order/export', {
        ...this.queryParams
      }, `list_order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
